package Views;

import Controllers.EmployeeController;
import Models.Employee;
import Models.EmptyValueException;
import java.awt.event.WindowEvent;
import javax.swing.event.ListSelectionEvent;

public class EmployeePanel extends ViewAbstract<Models.Employee>
{
	private Employee chosenSupervisor;

    public EmployeePanel(SearchableTabbedPane parent)
	{
        initComponents();
		this.controller = new EmployeeController();
		this.tabbedPane = parent;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        employeeNoL = new javax.swing.JLabel();
        employeeNoTF = new javax.swing.JTextField();
        nameL = new javax.swing.JLabel();
        nameTF = new javax.swing.JTextField();
        supervisorL = new javax.swing.JLabel();
        supervisorTF = new javax.swing.JTextField();
        addressL = new javax.swing.JLabel();
        addressTF = new javax.swing.JTextField();
        zipCodeL = new javax.swing.JLabel();
        zipCodeTF = new javax.swing.JTextField();
        cityL = new javax.swing.JLabel();
        cityTF = new javax.swing.JTextField();
        phoneNoL = new javax.swing.JLabel();
        phoneNoTF = new javax.swing.JTextField();
        searchTF = new javax.swing.JTextField();
        searchB = new javax.swing.JButton();
        employeePic = new javax.swing.JLabel();
        showAllB = new javax.swing.JButton();
        newB = new javax.swing.JButton();
        editB = new javax.swing.JButton();
        deleteB = new javax.swing.JButton();
        cancelB = new javax.swing.JButton();
        saveB = new javax.swing.JButton();
        chooseSupervisorB = new javax.swing.JButton();
        showSupervisorB = new javax.swing.JButton();
        Sep1 = new javax.swing.JSeparator();
        Sep2 = new javax.swing.JSeparator();
        Sep3 = new javax.swing.JSeparator();

        setMaximumSize(new java.awt.Dimension(600, 420));
        setMinimumSize(new java.awt.Dimension(600, 420));
        setName("Form"); // NOI18N

        employeeNoL.setText("MedarbNo.:");
        employeeNoL.setName("employeeNoL"); // NOI18N

        employeeNoTF.setEnabled(false);
        employeeNoTF.setMaximumSize(new java.awt.Dimension(200, 20));
        employeeNoTF.setMinimumSize(new java.awt.Dimension(200, 20));
        employeeNoTF.setName("employeeNoTF"); // NOI18N
        employeeNoTF.setNextFocusableComponent(nameTF);
        employeeNoTF.setPreferredSize(new java.awt.Dimension(200, 20));

        nameL.setText("Navn:");
        nameL.setName("nameL"); // NOI18N

        nameTF.setEnabled(false);
        nameTF.setMaximumSize(new java.awt.Dimension(200, 20));
        nameTF.setMinimumSize(new java.awt.Dimension(200, 20));
        nameTF.setName("nameTF"); // NOI18N
        nameTF.setNextFocusableComponent(supervisorTF);
        nameTF.setPreferredSize(new java.awt.Dimension(200, 20));

        supervisorL.setText("Overordnet:");
        supervisorL.setName("supervisorL"); // NOI18N

        supervisorTF.setEnabled(false);
        supervisorTF.setMaximumSize(new java.awt.Dimension(200, 20));
        supervisorTF.setMinimumSize(new java.awt.Dimension(200, 20));
        supervisorTF.setName("supervisorTF"); // NOI18N
        supervisorTF.setNextFocusableComponent(addressTF);
        supervisorTF.setPreferredSize(new java.awt.Dimension(200, 20));

        addressL.setText("Adresse:");
        addressL.setName("addressL"); // NOI18N

        addressTF.setEnabled(false);
        addressTF.setMaximumSize(new java.awt.Dimension(200, 20));
        addressTF.setMinimumSize(new java.awt.Dimension(200, 20));
        addressTF.setName("addressTF"); // NOI18N
        addressTF.setNextFocusableComponent(zipCodeTF);
        addressTF.setPreferredSize(new java.awt.Dimension(200, 20));

        zipCodeL.setText("PostNo.:");
        zipCodeL.setName("zipCodeL"); // NOI18N

        zipCodeTF.setEnabled(false);
        zipCodeTF.setMaximumSize(new java.awt.Dimension(200, 20));
        zipCodeTF.setMinimumSize(new java.awt.Dimension(200, 20));
        zipCodeTF.setName("zipCodeTF"); // NOI18N
        zipCodeTF.setNextFocusableComponent(cityTF);
        zipCodeTF.setPreferredSize(new java.awt.Dimension(200, 20));

        cityL.setText("By:");
        cityL.setName("cityL"); // NOI18N

        cityTF.setEnabled(false);
        cityTF.setMaximumSize(new java.awt.Dimension(200, 20));
        cityTF.setMinimumSize(new java.awt.Dimension(200, 20));
        cityTF.setName("cityTF"); // NOI18N
        cityTF.setNextFocusableComponent(phoneNoTF);
        cityTF.setPreferredSize(new java.awt.Dimension(200, 20));

        phoneNoL.setText("TelefonNo.:");
        phoneNoL.setName("phoneNoL"); // NOI18N

        phoneNoTF.setEnabled(false);
        phoneNoTF.setMaximumSize(new java.awt.Dimension(200, 20));
        phoneNoTF.setMinimumSize(new java.awt.Dimension(200, 20));
        phoneNoTF.setName("phoneNoTF"); // NOI18N
        phoneNoTF.setNextFocusableComponent(saveB);
        phoneNoTF.setPreferredSize(new java.awt.Dimension(200, 20));

        searchTF.setMaximumSize(new java.awt.Dimension(200, 20));
        searchTF.setMinimumSize(new java.awt.Dimension(200, 20));
        searchTF.setName("searchTF"); // NOI18N
        searchTF.setPreferredSize(new java.awt.Dimension(200, 20));

        searchB.setText("Søg");
        searchB.setName("searchB"); // NOI18N
        searchB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchBActionPerformed(evt);
            }
        });

        employeePic.setName("employeePic"); // NOI18N

        showAllB.setText("Vis Alle");
        showAllB.setName("showAllB"); // NOI18N
        showAllB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showAllBActionPerformed(evt);
            }
        });

        newB.setText("Ny");
        newB.setName("newB"); // NOI18N
        newB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newBActionPerformed(evt);
            }
        });

        editB.setText("Rediger");
        editB.setEnabled(false);
        editB.setName("editB"); // NOI18N
        editB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editBActionPerformed(evt);
            }
        });

        deleteB.setText("Slet");
        deleteB.setEnabled(false);
        deleteB.setName("deleteB"); // NOI18N
        deleteB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteBActionPerformed(evt);
            }
        });

        cancelB.setText("Annullér");
        cancelB.setEnabled(false);
        cancelB.setName("cancelB"); // NOI18N
        cancelB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelBActionPerformed(evt);
            }
        });

        saveB.setText("Gem");
        saveB.setEnabled(false);
        saveB.setName("saveB"); // NOI18N
        saveB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveBActionPerformed(evt);
            }
        });

        chooseSupervisorB.setText("Vælg");
        chooseSupervisorB.setEnabled(false);
        chooseSupervisorB.setName("chooseSupervisorB"); // NOI18N
        chooseSupervisorB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chooseSupervisorBActionPerformed(evt);
            }
        });

        showSupervisorB.setText("Vis");
        showSupervisorB.setEnabled(false);
        showSupervisorB.setName("showSupervisorB"); // NOI18N
        showSupervisorB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showSupervisorBActionPerformed(evt);
            }
        });

        Sep1.setName("Sep1"); // NOI18N

        Sep2.setName("Sep2"); // NOI18N

        Sep3.setOrientation(javax.swing.SwingConstants.VERTICAL);
        Sep3.setName("Sep3"); // NOI18N
        Sep3.setPreferredSize(new java.awt.Dimension(5, 23));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(supervisorL)
                            .addComponent(addressL)
                            .addComponent(zipCodeL)
                            .addComponent(cityL)
                            .addComponent(phoneNoL)
                            .addComponent(nameL)
                            .addComponent(employeeNoL))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(supervisorTF, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(chooseSupervisorB)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(showSupervisorB))
                            .addComponent(employeeNoTF, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(nameTF, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(addressTF, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(zipCodeTF, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cityTF, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(phoneNoTF, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(44, 44, 44)
                        .addComponent(employeePic, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(50, 50, 50))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(Sep1, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(searchTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(searchB)))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(Sep2, javax.swing.GroupLayout.DEFAULT_SIZE, 580, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(showAllB)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(Sep3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(newB)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(editB)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(deleteB)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 187, Short.MAX_VALUE)
                                .addComponent(cancelB)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(saveB)))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(searchB)
                            .addComponent(searchTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Sep1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(employeePic, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(employeeNoL)
                            .addComponent(employeeNoTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(nameL)
                            .addComponent(nameTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(supervisorL)
                            .addComponent(supervisorTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(chooseSupervisorB)
                            .addComponent(showSupervisorB))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(addressL)
                            .addComponent(addressTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(zipCodeL)
                            .addComponent(zipCodeTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cityL)
                            .addComponent(cityTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(phoneNoL)
                            .addComponent(phoneNoTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(68, 68, 68)))
                .addGap(93, 93, 93)
                .addComponent(Sep2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(showAllB)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(saveB)
                        .addComponent(cancelB)
                        .addComponent(newB)
                        .addComponent(editB)
                        .addComponent(deleteB))
                    .addComponent(Sep3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

	private void newBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newBActionPerformed
		clearComponents();
		changeComponentState(true);
		newOne = new Employee();
		newB.setEnabled(false);
		editB.setEnabled(false);
	}//GEN-LAST:event_newBActionPerformed

	private void editBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editBActionPerformed
		changeComponentState(true);
		newB.setEnabled(false);
		editB.setEnabled(false);
	}//GEN-LAST:event_editBActionPerformed

	private void deleteBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteBActionPerformed
		if(confirmDeletion("den ansatte"))
		{
			controller.delete(chosenOne.getEmployeeNo());
			clearComponents();
		}
	}//GEN-LAST:event_deleteBActionPerformed
	
	private void cancelBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBActionPerformed
		clearComponents();
		changeComponentState(false);
	}//GEN-LAST:event_cancelBActionPerformed

	private void saveBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBActionPerformed
		Employee theOne = getTheOne();

		try
		{
			theOne.setData(nameTF.getText(), addressTF.getText(), zipCodeTF.getText(), phoneNoTF.getText());
			if(chosenSupervisor != null)
			{
				theOne.setSupervisor(chosenSupervisor);
			}

			if(chosenOne == null)
			{
				controller.insert(theOne);
			}
			else
			{
				controller.update(theOne, "employeeNo = "+theOne.getEmployeeNo());
			}
		}
		catch (EmptyValueException e)
		{
			informAboutEmptyFields();
			return;
		}
		catch (NumberFormatException e)
		{
			informAboutWrongInput("Postnummer og telefonnummer skal være heltal.", "Forkert information");
			return;
		}

		informSavingWentOk("Den ansatte");
		clearComponents();
		changeComponentState(false);
		newB.setEnabled(true);
	}//GEN-LAST:event_saveBActionPerformed

	private void searchBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchBActionPerformed
		tabbedPane.search(TabIndex.Employees, searchTF.getText());
	}//GEN-LAST:event_searchBActionPerformed

	private void showAllBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showAllBActionPerformed
		tabbedPane.search(TabIndex.Employees, "*");
	}//GEN-LAST:event_showAllBActionPerformed

	private void chooseSupervisorBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseSupervisorBActionPerformed
		if(picker == null)
		{
			picker = createPicker(TabIndex.Employees);
			picker.addWindowListener(this);
			picker.setVisible(true);
		}
}//GEN-LAST:event_chooseSupervisorBActionPerformed

	private void showSupervisorBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showSupervisorBActionPerformed
		tabbedPane.switchTabWithNo(TabIndex.Employees, chosenSupervisor.getEmployeeNo());
}//GEN-LAST:event_showSupervisorBActionPerformed

	protected void changeComponentState(boolean state)
	{
		nameTF.setEnabled(state);
		addressTF.setEnabled(state);
		zipCodeTF.setEnabled(state);
		phoneNoTF.setEnabled(state);
		chooseSupervisorB.setEnabled(state);
		showSupervisorB.setEnabled(chosenSupervisor != null);
		cancelB.setEnabled(state);
		saveB.setEnabled(state);
		setUnsavedState(state);
	}

	protected void populateFields()
	{
		employeeNoTF.setText(String.valueOf(chosenOne.getEmployeeNo()));
		nameTF.setText(String.valueOf(chosenOne.getName()));
		addressTF.setText(chosenOne.getAddress());
		zipCodeTF.setText(String.valueOf(chosenOne.getZipCode()));
		cityTF.setText(chosenOne.getCity());
		phoneNoTF.setText(String.valueOf(chosenOne.getPhoneNo()));
		if(chosenOne.getSupervisor() != null)
		{
			chosenSupervisor = chosenOne.getSupervisor();
			supervisorTF.setText(chosenSupervisor.getName());
			showSupervisorB.setEnabled(true);
		}
		else
		{
			chosenSupervisor = null;
			supervisorTF.setText("");
			showSupervisorB.setEnabled(false);
		}

		newB.setEnabled(true);
		editB.setEnabled(true);
		deleteB.setEnabled(true);
	}

	protected void clearComponents()
	{
		chosenOne = null;
		newOne = null;
		employeeNoTF.setText("");
		nameTF.setText("");
		supervisorTF.setText("");
		showSupervisorB.setEnabled(false);
		addressTF.setText("");
		zipCodeTF.setText("");
		phoneNoTF.setText("");
		chosenSupervisor = null;
		newB.setEnabled(true);
		editB.setEnabled(false);
		deleteB.setEnabled(false);
	}

	protected void showNo(int no)
	{
		chosenOne = controller.find(no);
		populateFields();
	}

	public void valueChanged(ListSelectionEvent e)
	{}

	public void windowClosing(WindowEvent e)
	{
		if(picker != null)
		{
			Employee supervisor = (Employee)picker.getTheChosenOne();
			if(supervisor != null)
			{
				this.setChosenSupervisor(supervisor);
			}
			this.releasePicker();
		}
	}

	public void setChosenSupervisor(Employee chosenSupervisor)
	{
		this.chosenSupervisor = chosenSupervisor;
		if(chosenSupervisor != null)
		{
			supervisorTF.setText(chosenSupervisor.getName());
			showSupervisorB.setEnabled(true);
		}
		else
		{
			supervisorTF.setText("");
			showSupervisorB.setEnabled(false);
		}
	}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JSeparator Sep1;
    private javax.swing.JSeparator Sep2;
    private javax.swing.JSeparator Sep3;
    private javax.swing.JLabel addressL;
    private javax.swing.JTextField addressTF;
    private javax.swing.JButton cancelB;
    private javax.swing.JButton chooseSupervisorB;
    private javax.swing.JLabel cityL;
    private javax.swing.JTextField cityTF;
    private javax.swing.JButton deleteB;
    private javax.swing.JButton editB;
    private javax.swing.JLabel employeeNoL;
    private javax.swing.JTextField employeeNoTF;
    private javax.swing.JLabel employeePic;
    private javax.swing.JLabel nameL;
    private javax.swing.JTextField nameTF;
    private javax.swing.JButton newB;
    private javax.swing.JLabel phoneNoL;
    private javax.swing.JTextField phoneNoTF;
    private javax.swing.JButton saveB;
    private javax.swing.JButton searchB;
    private javax.swing.JTextField searchTF;
    private javax.swing.JButton showAllB;
    private javax.swing.JButton showSupervisorB;
    private javax.swing.JLabel supervisorL;
    private javax.swing.JTextField supervisorTF;
    private javax.swing.JLabel zipCodeL;
    private javax.swing.JTextField zipCodeTF;
    // End of variables declaration//GEN-END:variables
}